/*
// Definition for Employee.
class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
};
*/

class Solution {
    public int getImportance(List<Employee> employees, int id) {
        /* 边界: 下属为空 
            每次先加第一个下属的重要性 
            按照相同的操作再去加下属的第一个下属的重要性 
        */ 
        if(employees.isEmpty()){
            return 0;
        }
        Map<Integer,Employee> map = new HashMap<>();
        for(Employee e : employees){
            map.put(e.id, e);
        }
        return Dfs(id, map);
    }
    public int dfs(int id, Map<Integer,Employee> map){
            Employee employee = map.get(id);
            int curSum = employee.importance;

            for(Integer curId : employee.subordinates){
                curSum += Dfs(curId, map);
            }
            return curSum;
        }
}